<template>
  <div class="update1234">
    <!-- 输入密码 -->
    <van-field  type="password" label="旧密码" placeholder="请输入初始密码" v-model="fareStartPassword"/>
    <van-field  type="password" label="新密码" placeholder="请设置新密码" v-model="farePassword"/>
    <van-field v-model="confirmPassword" label="确认新密码" type="password" placeholder="请确认密码"/>
    <van-button type="primary" size="large" @click="findPassword">确认</van-button>
    <BottomPanel/>
  </div>
</template>

<script>
import BottomPanel from "@/views/bottomPanel.vue";
import {updatePassword} from "@/api/personal/personal";
import {isOldPasswordCorrect} from "@/api/personal/personal";

export default {
  methods: {
    findPassword(){
      // 判断旧密码是否正确
      isOldPasswordCorrect(this.passengerId,this.fareStartPassword).then(res => {
          console.log(res)
          if (this.fareStartPassword!=null)
          {
            this.fareStartPassword=res.fareStartPassword;
          }else{
            this.$toast('初始密码不能为空');
            if (res!=this.fareStartPassword)
            this.$toast('初始密码错误');
          }
        })
      updatePassword(this.passengerId,this.farePassword,this.confirmPassword).then(res => {
        // 检查新密码和确认密码是否一致
      if (this.farePassword!=null)
      {
        this.farePassword=res.farePassword;
      }else{
        this.$toast('新密码不能为空');
        if (this.farePassword!== this.confirmPassword) {
          this.$toast('新密码和确认密码不一致');
        }
      }
      })
      this.$router.push({path: '/personalHome'})
    },
  },
  data() {
    return {
      passengerId:1,
      farePassword:'',
      fareStartPassword:'',
      confirmPassword:''
    }
  },
  components: {BottomPanel},

}
</script>


<style>
.update1234{
  width: 100%;
  height: 100vh;
}
</style>